<?php
declare(strict_types=1);

namespace App\Logic;

use App\Event\AdministratorLogsEvent;
use App\Models\Config as ConfigModel;

class Config
{
    public function select()
    {
        $result = [];
        $config = ConfigModel::select('config_name','config_value')->get();
        foreach ($config as $item) {
            $result[$item['config_name']] = $item['config_value'];
        }
        return $result;
    }

    public function update(array $data)
    {
        foreach ($data as $key => $value) {
            $config = ConfigModel::where('config_name', $key)->first();
            $config->config_value = $value;
            if (!$config->save()) return false;
        }
        event(new AdministratorLogsEvent("修改系统基本设置"));
        return true;
    }
}
